import { createStore } from 'vuex';

export default createStore({
  state: {
    user: {
      name: '测试',
      age: 18,
      height: 185
    }
  },
  mutations: {
    //mutations：保存所有方法，通过commit触发 用来改变state的数据  参数一默认state
    changeUser(state, val) {
      state.user.name = val;
    }
  },
  actions: {
    //actions: 通过dispatch异步提交触发mutations里面的方法
    changeName({ commit }, payload) {
      commit('changeUser', payload);
    }
  },
  modules: {}
});
